package CodeThree;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
/** @author ASUS */
public class Supplicates {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int offer = 3;
    int collection = 2;
    int m = scanner.nextInt();
    int n = scanner.nextInt();
    int[][] a = new int[m][offer];
    int[][] b = new int[n][collection];
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < offer; j++) {
        a[i][j] = scanner.nextInt();
      }
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < collection; j++) {
        b[i][j] = scanner.nextInt();
      }
    }
    // TODO 了解排序原因
    // 按照运费从小到大排序（冒泡）
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m - i - 1; j++) {
        if (a[j + 1][2] < a[j][2]) {
          int t = a[j + 1][0];
          a[j + 1][0] = a[j][0];
          a[j][0] = t;

          t = a[j + 1][1];
          a[j + 1][1] = a[j][1];
          a[j][1] = t;

          t = a[j + 1][2];
          a[j + 1][2] = a[j][2];
          a[j][2] = t;
        }
      }
    }

    // 第二种排序方式  Java自定义排序 基于 lambda 表达式 创建Comparator
    Arrays.sort(a, Comparator.comparingInt(c -> c[2]));

    int summer = 0;
    int summable = 0;

    for (int i = 0; i < m; i++) {
      summer += a[i][1];
    }
    for (int i = 0; i < n; i++) {
      summable += b[i][1];
    }
    if (summer < summable) {
      System.out.println("-1");
    } else {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (a[j][1] == 0) {
            continue;
          }

          if (a[j][1] < b[i][1]) {
            System.out.println(a[j][0] + " " + b[i][0] + " " + a[j][1]);
            b[i][1] -= a[j][1];
            a[j][1] = 0;
            continue;
          }

          if (a[j][1] >= b[i][1]) {
            System.out.println(a[j][0] + " " + b[i][0] + " " + b[i][1]);
            a[j][1] -= b[i][1];
            b[i][1] = 0;
            break;
          }
        }
      }
    }
  }
}
